var liBtn = document.querySelectorAll(".menu_left_list_li");
var heardLi = document.querySelectorAll(".heard_box2_list_li");
var heardSpan = document.querySelectorAll(".heard_box2_list_span");
var btnRight = document.querySelectorAll(".menu_right_span3");
var btnLeft = document.querySelectorAll(".menu_right_span1");
var oneNumber = document.querySelectorAll(".menu_right_span2");
var allNumber = document.querySelector(".number");
var menuList = document.querySelectorAll('.menu_right_list')
var menuBox = document.querySelector('.menu_right')
var allNum = 0;

//点击头部菜单切换类
var saveHeardSpan = heardSpan[0];
for (var i = 0; i < heardLi.length; i++) {
    heardLi[i].index = i;
    heardLi[i].onclick = function () {
        saveHeardSpan.classList.remove("add_span");
        heardSpan[this.index].classList.add("add_span");
        saveHeardSpan = heardSpan[this.index];
    };
}
//点击按钮控制数量
for (var i = 0; i < oneNumber.length; i++) {
    btnRight[i].index = i;
    btnRight[i].onclick = function () {
        var btn = "right";
        //去掉disnone类
        if (
            oneNumber[this.index].classList.contains("disnone") &&
            btnLeft[this.index].classList.contains("disnone")
        ) {
            oneNumber[this.index].classList.remove("disnone");
            btnLeft[this.index].classList.remove("disnone");
        }
        //按钮加oneNumber
        var oneNum = oneNumber[this.index].innerText;
        oneNum++;
        oneNumber[this.index].innerText = oneNum;
        allMoney(btn);
    };
    btnLeft[i].index = i;
    btnLeft[i].onclick = function () {
        var btn = "left";
        //按钮减oneNumber
        var oneNum = oneNumber[this.index].innerText;
        oneNum--;
        oneNumber[this.index].innerText = oneNum;
        if (oneNum <= 0) {
            if (!oneNumber[this.index].classList.contains("disnone")) {
                oneNumber[this.index].classList.add("disnone");
                btnLeft[this.index].classList.add("disnone");
            }
        }
        allMoney(btn);
    };
}
function allMoney(btn) {
    if (btn == "right") {
        allNum++;
        allNumber.innerText = allNum;
    }
    if (btn == "left") {
        allNum--;
        allNumber.innerText = allNum;
    }
}
//点击右边菜单切换类
var saveLi = liBtn[0];
for (var i = 0; i < liBtn.length; i++) {
    liBtn[i].index = i
    liBtn[i].onclick = function () {
        saveLi.classList.remove("isCk");
        this.classList.add("isCk");
        saveLi = this;
        menuBox.scrollTop = menuList[this.index].offsetTop
    };
}
// 滑动左菜单栏到对应右栏框

menuBox.onscroll = function () {
    var index = 0
    for (var i = 0; i < menuList.length; i++) {
        if (Math.ceil(menuBox.scrollTop) >= menuList[index].offsetHeight + menuList[index].offsetTop) {
            index = i
        }
        saveLi.classList.remove("isCk")
        liBtn[index].classList.add("isCk")
        saveLi = liBtn[index]
        tj = false
        console.log(index);
    }
}